package com.itrus.cert;

import com.itrus.util.CertUtils;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigInteger;
import java.security.cert.CertificateEncodingException;
import java.security.cert.CertificateException;
import java.security.cert.CertificateParsingException;
import java.util.Date;
import java.util.Iterator;
import java.util.Set;
import java.util.Vector;
import javax.servlet.http.HttpServletRequest;
import org.bouncycastle.asn1.ASN1InputStream;
import org.bouncycastle.asn1.ASN1Sequence;
import org.bouncycastle.asn1.cms.IssuerAndSerialNumber;
import org.bouncycastle.asn1.x509.X509CertificateStructure;
import org.bouncycastle.jce.provider.X509CertificateObject;
import org.bouncycastle.util.encoders.Base64;

public class X509Certificate extends X509CertificateObject
{
  public static String AccountHashOID = "1.2.156.112535.1.2.1";
  protected static String certAttrName = "javax.servlet.request.X509Certificate";
  private static final long serialVersionUID = -6185937594117975468L;

  public X509Certificate(X509CertificateStructure paramX509CertificateStructure)
    throws CertificateParsingException
  {
    super(paramX509CertificateStructure);
  }

  private static X509Certificate engineGenerateCertificate(InputStream paramInputStream)
    throws CertificateException
  {
    try
    {
      if (!paramInputStream.markSupported())
        paramInputStream = new BufferedInputStream(paramInputStream);
      paramInputStream.mark(10);
      int i = paramInputStream.read();
      if (i == -1)
        return null;
      if (i != 48)
      {
        paramInputStream.reset();
        return readPEMCertificate(paramInputStream);
      }
      if (paramInputStream.read() == 128)
      {
        paramInputStream.reset();
        return readPKCS7Certificate(paramInputStream);
      }
      paramInputStream.reset();
      X509Certificate localX509Certificate = readDERCertificate(paramInputStream);
      return localX509Certificate;
    }
    catch (Exception localException)
    {
      throw new CertificateException(localException.toString());
    }
  }

  public static X509Certificate getInstance(InputStream paramInputStream)
    throws CertificateException
  {
    return engineGenerateCertificate(paramInputStream);
  }

  public static X509Certificate getInstance(String paramString)
    throws CertificateException
  {
    return engineGenerateCertificate(new ASN1InputStream(paramString.getBytes()));
  }

  public static X509Certificate getInstance(java.security.cert.X509Certificate paramX509Certificate)
    throws CertificateEncodingException, CertificateException
  {
    return getInstance(paramX509Certificate.getEncoded());
  }

  public static X509Certificate getInstance(byte[] paramArrayOfByte)
    throws CertificateException
  {
    return engineGenerateCertificate(new ASN1InputStream(paramArrayOfByte));
  }

  public static X509Certificate getInstanceFromFile(String paramString)
    throws FileNotFoundException, CertificateException
  {
    return engineGenerateCertificate(new FileInputStream(paramString));
  }

  public static X509Certificate getInstanceFromHttpsClient(HttpServletRequest paramHttpServletRequest)
    throws CertificateException
  {
    if (paramHttpServletRequest.getAttribute(certAttrName) == null)
      return null;
    return getInstance(((java.security.cert.X509Certificate[])paramHttpServletRequest.getAttribute(certAttrName))[0].getEncoded());
  }

  private static X509Certificate readDERCertificate(InputStream paramInputStream)
    throws IOException, CertificateParsingException
  {
    return new X509Certificate(X509CertificateStructure.getInstance((ASN1Sequence)new ASN1InputStream(paramInputStream).readObject()));
  }

  private static String readLine(InputStream paramInputStream)
    throws IOException
  {
    StringBuffer localStringBuffer = new StringBuffer();
    while (true)
    {
      int i = paramInputStream.read();
      if ((i == 10) || (i < 0))
      {
        if ((localStringBuffer.length() != 0) || (i >= 0))
          break;
        return null;
      }
      if (i != 13)
        localStringBuffer.append((char)i);
    }
    return localStringBuffer.toString();
  }

  private static X509Certificate readPEMCertificate(InputStream paramInputStream)
    throws IOException, CertificateParsingException
  {
    StringBuffer localStringBuffer = new StringBuffer();
    while (true)
    {
      String str = readLine(paramInputStream);
      if (str == null)
      {
        if (localStringBuffer.length() == 0)
          break;
        return readDERCertificate(new ByteArrayInputStream(Base64.decode(localStringBuffer.toString())));
      }
      if ((!str.equals("-----BEGIN CERTIFICATE-----")) && (!str.equals("-----BEGIN X509 CERTIFICATE-----")) && (!str.equals("-----END CERTIFICATE-----")) && (!str.equals("-----END X509 CERTIFICATE-----")))
        localStringBuffer.append(str);
    }
    return null;
  }

  private static X509Certificate readPKCS7Certificate(InputStream paramInputStream)
    throws IOException, CertificateParsingException
  {
    return new X509Certificate(X509CertificateStructure.getInstance((ASN1Sequence)new ASN1InputStream(paramInputStream).readObject()));
  }

  public String getAccountHash()
  {
    byte[] arrayOfByte = CertUtils.getExtensionValue(this, AccountHashOID);
    if (arrayOfByte != null)
      return new String(arrayOfByte);
    return null;
  }

  public String getAlias()
  {
    CertNames localCertNames = getCertSubjectNames();
    String str = localCertNames.getItem("CN");
    if (str == null)
    {
      Iterator localIterator = localCertNames.keySet().iterator();
      if (localIterator.hasNext())
        str = (String)localCertNames.getItems((String)localIterator.next()).get(0);
    }
    return str;
  }

  public String getCRLDistributionPointURL()
  {
    try
    {
      String str = CertUtils.getCRLDistributionPointURL(this);
      return str;
    }
    catch (IOException localIOException)
    {
      localIOException.printStackTrace();
    }
    return null;
  }

  public String getCertID()
  {
    return CertUtils.getCertID(this);
  }

  public CertNames getCertIssuerNames()
  {
    return CertUtils.parseCertDistinguishName(getIssuerDNString(), null);
  }

  public CertNames getCertSubjectNames()
  {
    return CertUtils.parseCertDistinguishName(getSubjectDNString(), null);
  }

  public String getHexSerialNumber()
  {
    return CertUtils.getIEValidSerialNumber(getSerialNumber().toString(16));
  }

  public String getICAIssuerDNString()
  {
    return getIssuerDNString().replaceFirst("E=", "emailAddress=");
  }

  public String getICASerialNumber()
  {
    return CertUtils.getICAValidSerialNumber(getSerialNumber().toString(16));
  }

  public String getICASubjectDNString()
  {
    return getSubjectDNString().replaceFirst("E=", "emailAddress=");
  }

  public IssuerAndSerialNumber getIssuerAndSerialNumber()
  {
    return CertUtils.getIssuerAndSerialNumber(this);
  }

  public String getIssuerDNString()
  {
    return CertUtils.getX509NameString(getIssuerX500Principal());
  }

  public Names getIssuerNames()
  {
    return CertUtils.parseDistinguishName(getIssuerDNString(), null);
  }

  public String getSubjectDNString()
  {
    return CertUtils.getX509NameString(getSubjectX500Principal());
  }

  public Names getSubjectNames()
  {
    return CertUtils.parseDistinguishName(getSubjectDNString(), null);
  }

  public boolean isOnValidPeriod()
  {
    Date localDate1 = getNotBefore();
    Date localDate2 = getNotAfter();
    Date localDate3 = new Date();
    return (!localDate3.before(localDate1)) && (!localDate3.after(localDate2));
  }

  public boolean verify(X509Certificate paramX509Certificate)
  {
    try
    {
      verify(paramX509Certificate.getPublicKey());
      return true;
    }
    catch (Exception localException)
    {
    }
    return false;
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.itrus.cert.X509Certificate
 * JD-Core Version:    0.6.2
 */